<!--# layout("/common/layout.html",{"jsBase":"/js/trans/eolrefund/"}){ -->

<form class="layui-form layui-form-pane" id="addForm"  lay-filter="editform">
    <input type="hidden" name="refundId" id="refundId">
    <input type="hidden" name="tranId" id="tranId" value="${base.tranId}">

    <br>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">交易单号</label>
				<div class="layui-input-inline">
                      <input type="text" name="transactionId" id="transactionId" autocomplete="off" style="width: 300px" class="layui-input" readonly>
				</div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 120px">退款金额(分)</label>
                    <div class="layui-input-inline">
                                    <input type="text" name="refundApply" id="refundApply" autocomplete="off" class="layui-input" readonly>
                    </div>
             </div>

            <div class="layui-inline">
                <label class="layui-form-label">退款状态</label>
                <div class="layui-input-inline">
                    <select style="width:40%" class="select" name="refundStatus" id="refundStatus"  promtion="请选择" lay-verify="" disabled>
                        <option value="">请选择</option>
                        <option value="1" ${base.refundStatus==1?'select':''}>申请中</option>
                        <option value="2" ${base.refundStatus==2?'select':''}>审核驳回</option>
                        <option value="3" ${base.refundStatus==3?'select':''}>审核通过</option>
                        <option value="4" ${base.refundStatus==4?'select':''}>已退款</option>
                        <option value="-4" ${base.refundStatus==-4?'select':''}>退款时接口异常</option>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">订单类型</label>
                <div class="layui-input-inline">
                   <span style="line-height:38px;margin-left:8px" id="univTypeSpan">
                           ${base.orderName}
                    </span>
                </div>
            </div>

        </div>

    </div>

    <div class="layui-row">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">申请类型</label>
                <div class="layui-input-inline">
                    <select style="width:40%" class="select" name="applyType" id="applyType"  promtion="请选择" lay-verify="" disabled>
                        <option value="">请选择</option>
                        <option value="a" ${base.applyType=='a'?'select':''}>会员申请</option>
                        <option value="b" ${base.applyType=='b'?'select':''}>后台操作</option>
                    </select>
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">支付类型</label>
                <div class="layui-input-inline">
                    <select style="width:40%" class="select" name="payMethod" id="payMethod"  promtion="请选择" lay-verify="" disabled>
                        <option value="">请选择</option>
                        <option value="1" ${base.payMethod==1?'selected':''}>微信h5支付</option>
                        <option value="2" ${base.payMethod==2?'selected':''}>微信公众号支付</option>
                        <option value="3" ${base.payMethod==3?'selected':''}>微信小程序支付</option>
                        <option value="4" ${base.payMethod==4?'selected':''}>微信扫码支付</option>
                        <option value="11" ${base.payMethod==11?'selected':''}>支付宝h5支付</option>
                        <option value="21" ${base.payMethod==21?'selected':''}>银联支付</option>
                        <option value="31" ${base.payMethod==31?'selected':''}>7天网络支付</option>
                    </select>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">交易备注</label>
                <textarea name="tradeMemo" placeholder="" rows=3  style="width: 500px" class="layui-textarea" readonly>${base.tradeMemo}</textarea>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">购买记录</label>
                <textarea name="" placeholder="" rows=3  style="width: 500px" class="layui-textarea" readonly>${tranRecord}</textarea>
            </div>

        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
            <label class="layui-form-label">退款原因</label>
                    <textarea name="refundReason" placeholder="" rows=3  style="width: 500px" class="layui-textarea" readonly>${base.refundReason}</textarea>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">退款记录</label>
                <textarea name="" placeholder="" rows=3  style="width: 500px" class="layui-textarea" readonly>${refundRecordStr}</textarea>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">附  件</label>
                    <!--#for(img in imgs){  -->
                       <!-- <div class="layui-input-inline">
                                <img class="imgclass"  id="" src="${img.fileUrl}" width="50%">
                        </div>-->
                            <a data-gallery="manual" href="${img.fileUrl}" data-group="a" class="layui-input-inline">
                                <img src="${img.fileUrl}" alt="" width="50%">
                            </a>
                    <!--#} -->
            </div>
            <div id="outerdiv" style="position:fixed;top:0;left:0;background:rgba(0,0,0,0.7);z-index:2;width:100%;height:100%;display:none;">
                <div id="innerdiv" style="position:absolute;">
                    <img id="bigimg" style="border:5px solid #fff;" src="" />
                </div>
            </div>
        </div>
    </div>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">处理意见</label>
                <div class="layui-input-inline">
                    <textarea name="handleMemo" id="handleMemo" placeholder="请输入意见" rows=4  style="width: 500px" class="layui-textarea"></textarea>
                </div>
            </div>
        </div>
    </div>

    <button class="layui-btn layui-btn-normal" type="button" id="addButton" lay-submit="" lay-filter="form">通过</button>
    <button class="layui-btn layui-btn-warm" type="button" id="overruleButton" lay-submit="" lay-filter="form">驳回</button>
    <button class="layui-btn layui-btn-danger" type="button" id="refundButton" lay-submit="" lay-filter="form">退款</button>
    <button class="layui-btn" type="button" id="addButton-cancel">取消</button>
</form>
<!--#} -->
<link href="${ctxPath}/css/photoviewer.css" rel="stylesheet">
<script type="text/javascript"  src="${ctxPath}/plugins/photoview/photoviewer.js"></script>
<script>
layui.define([ 'form', 'laydate', 'table','refundApi'], function(exports) {
    var form = layui.form;
    var refundApi = layui.refundApi;
    var index = layui.index;
    var isNew = true;
    <!--# if(!(isEmpty(refundJson))){  -->
    isNew = false;
    <!--# } -->
    // $('.imgclass').click(function () {
    //     var _this = $(this);//将当前的pimg元素作为_this传入函数
    //     imgShow("#outerdiv", "#innerdiv", "#bigimg", _this);
    // });
    $('[data-gallery=manual]').click(function (e) {

        e.preventDefault();
        console.log( $(this).index());
        var items = [],
            options = {
                index: $(this).index()-1
            };

        $('[data-gallery=manual]').each(function () {
            items.push({
                src: $(this).attr('href'),
                // title: $(this).attr('data-title')
            });
        });

        new PhotoViewer(items, options);

    });
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                //审核通过
                var handleMemo=$("#handleMemo").val();
                var refundId=$("#refundId").val();
                console.log(refundId);
                $.ajax({
                    type: "POST",
                    url: "${ctxPath}/trans/refund/auditSuccess.json",
                    data: {
                        refundId:refundId,
                        handleMemo:handleMemo
                    },
                    dataType: "JSON" ,
                    async:false,
                    // contentType: "application/json; charset=utf-8",
                    success: function (message) {
                        if(message.code == 0){
                            parent.window.dataReload();
                            Common.success("审核成功");
                            Lib.closeFrame();
                        }else{
                            parent.window.dataReload();
                            Common.info(message.msg);
                            Lib.closeFrame();
                        }

                    },
                    error: function (message) {
                    }
                });
            });

            $("#overruleButton").click(function(){
                //驳回
                var handleMemo=$("#handleMemo").val();
                var refundId=$("#refundId").val();

                if(handleMemo==null||handleMemo==""){
                    Common.info("处理意见不能为空");
                    return ;
                }
                if(handleMemo.length<10){
                    Common.info("处理意见不能少于10个字");
                    return ;
                }
                $.ajax({
                    type: "POST",
                    url: "${ctxPath}/trans/refund/auditFail.json",
                    data: {
                        refundId:refundId,
                        handleMemo:handleMemo
                    },
                    dataType: "JSON" ,
                    async:false,
                    // contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        if(data.code == 0){
                            parent.window.dataReload();
                            Common.success("驳回成功");
                            Lib.closeFrame();
                        }else{
                            parent.window.dataReload();
                            Common.info(data.msg);
                            Lib.closeFrame();
                        }
                    },
                    error: function (message) {
                    }
                });
            });

            $("#refundButton").click(function(){
                //退款
                var handleMemo=$("#handleMemo").val();
                var refundId=$("#refundId").val();
                var tranId = $("#tranId").val();
                var refundApply = $("#refundApply").val();
                var origin = window.location.origin;
                var url = "${ctxPath}/trans/refund/refund.json";
                if(origin.indexOf("qitian.51sdx.com")>=0){
                    url = "${ctxPath}/trans/refund/qtrefund.json";
                }

                Common.openConfirm("确认要进行退款操作?",function(){
                    $.ajax({
                        type: "POST",
                        url: url,
                        data: {
                            refundId:refundId,
                            handleMemo:handleMemo,
                            tranId:tranId,
                            refundMoney:refundApply
                        },
                        dataType: "JSON" ,
                        async:false,
                        // contentType: "application/json; charset=utf-8",
                        success: function (data) {
                            if(data.code == 0){
                                setTimeout(function(){
                                    parent.window.dataReload();
                                    Common.success(data.msg);
                                    Lib.closeFrame();
                                }, 3000);
                            }else{
                                parent.window.dataReload();
                                Common.info( data.msg);
                                Lib.closeFrame();
                            }
                        },
                        error: function (message) {
                        }
                    });
                })


            });


            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
    <!--# if(!(isEmpty(refundJson))){  -->
    var formJson = ${refundJson};
    form.val("editform",formJson);
    <!--# } -->


    function imgShow(outerdiv, innerdiv, bigimg, _this){
        var src = _this.attr("src");//获取当前点击的pimg元素中的src属性
        $(bigimg).attr("src", src);//设置#bigimg元素的src属性

        /*获取当前点击图片的真实大小，并显示弹出层及大图*/
        $("<img/>").attr("src", src).load(function(){
            var windowW = $(window).width();//获取当前窗口宽度
            var windowH = $(window).height();//获取当前窗口高度
            var realWidth = this.width;//获取图片真实宽度
            var realHeight = this.height;//获取图片真实高度
            var imgWidth, imgHeight;
            var scale = 0.9;//缩放尺寸，当图片真实宽度和高度大于窗口宽度和高度时进行缩放

            if(realHeight>windowH*scale) {//判断图片高度
                imgHeight = windowH*scale;//如大于窗口高度，图片高度进行缩放
                imgWidth = imgHeight/realHeight*realWidth;//等比例缩放宽度
                if(imgWidth>windowW*scale) {//如宽度扔大于窗口宽度
                    imgWidth = windowW*scale;//再对宽度进行缩放
                }
            } else if(realWidth>windowW*scale) {//如图片高度合适，判断图片宽度
                imgWidth = windowW*scale;//如大于窗口宽度，图片宽度进行缩放
                imgHeight = imgWidth/realWidth*realHeight;//等比例缩放高度
            } else {//如果图片真实高度和宽度都符合要求，高宽不变
                imgWidth = realWidth;
                imgHeight = realHeight;
            }
            $(bigimg).css("width",imgWidth);//以最终的宽度对图片缩放

            var w = (windowW-imgWidth)/2;//计算图片与窗口左边距
            var h = (windowH-imgHeight)/2;//计算图片与窗口上边距
            $(innerdiv).css({"top":h, "left":w});//设置#innerdiv的top和left属性
            $(outerdiv).fadeIn("fast");//淡入显示#outerdiv及.pimg
        });

        $(outerdiv).click(function(){//再次点击淡出消失弹出层
            $(this).fadeOut("fast");
        });
    }

});
</script>
